// 头部分析师选中
$('.header_l ul li a').css({'border-bottom':'0px #fff','color':'#20222c'});
$('.header_l ul li:eq(1) a').css({'border-bottom':'2px solid #04b1f9','color':'#04b1f9'});
$(".header_l ul li").mouseenter(function () {
  $(this).find("a").css({'color':'#04b1f9'});
}).mouseleave(function () {
  $(this).find("a").css({'color':'#20222c'});
  $('.header_l ul li:eq(1) a').css({'border-bottom':'2px solid #04b1f9','color':'#04b1f9'});
});

// 小banner
$(function(){
	var screen = $('.l_schlist');
	var ul = $('.schlist')[0];
	var lis = $('.schlist').children();
	var liWidth = $('.schlist>li').width()+26;
	var aright = $('a.aright')[0];
	var aleft = $('a.aleft')[0];
	var index=ingindex-1;
	aright.onclick=function(){
		if(index < lis.length-4) {
			index++;
			animate(ul,-index*liWidth);
			$('a.aleft').css({'background-color':'rgb(247, 51, 83)','cursor':'pointer','color':'#fff'});
		}else{
			$('a.aright').css({'background-color':'#d0d0d0','cursor':'default','color':'#797979'});
		}
	}
	aleft.onclick=function(){
		if(index > 0) {
			index--;
			animate(ul,-index*liWidth);
			$('a.aright').css({'background-color':'rgb(247, 51, 83)','cursor':'pointer','color':'#fff'});
		}else{
			$('a.aleft').css({'background-color':'#d0d0d0','cursor':'default','color':'#797979'});
		}
	}

	function animate(element,target) {
		clearInterval(element.setId);
		element.setId=setInterval(function(){
			var current = element.offsetLeft;
			var step = 10;
			step=current<target?step:-step;
			current +=step;
			if(Math.abs(target-current)<=Math.abs(step)){
				element.style.left=target+'px';
				clearInterval(element.setId);
			}else{
				element.style.left=current+'px';
			}
		},20);
	}
	$('.l_arrange').mouseover(function(){
		$('a.abtn').show();
	})
	$('.l_arrange').mouseout(function(){
		$('a.abtn').hide();
	})
})

//复制链接
$(function(){
	var clipboard = new Clipboard('#cp-btn');
    clipboard.on('success', function(e) {
        layer.tips('复制成功','#cp-btn',{time:1000}) 
        e.clearSelection(); 
    });
    clipboard.on('error', function(e) { 
        layer.tips('复制失败，请手动复制','#cp-btn',{time:1000}) 
    });
})
// 页面内定位
$(function(){
    $("#topaiming").click(function() {
     	$(this).attr('class','current').siblings().attr('class','');
        $("html, body").animate({
            scrollTop: $("#paiming").offset().top }, {duration: 500,easing: "swing"});
        return false;
    });
    $("#tojiangxiang").click(function() {
    	$(this).attr('class','current').siblings().attr('class','');
        $("html, body").animate({
            scrollTop: $("#jiangxiang").offset().top }, {duration: 500,easing: "swing"});
        return false;
    });
    $("#toguize").click(function() {
    	$(this).attr('class','current').siblings().attr('class','');
        $("html, body").animate({
            scrollTop: $("#guize").offset().top }, {duration: 500,easing: "swing"});
        return false;
    })
    $("#toyaoqing").click(function() {
    	$(this).attr('class','current').siblings().attr('class','');
        $("html, body").animate({
            scrollTop: $("#yaoqing").offset().top }, {duration: 500,easing: "swing"});
        return false;
    })
})

// 回到顶部
$(function () {
    $(window).scroll(function () {
        if ($(window).scrollTop() >= $("#l_wrapper").height()) {
            $("#returnTop").css("display", "block");
        } else {
            $("#returnTop").css("display", "none");
        }
    });
    var speed=200;
    $("#returnTop").click(function () {
        $('body,html').animate({"scrollTop": "0"}, speed);
         return false;
    });
});
// 固定导航栏
$(function () {
    //滚动条的事件绑定
    $(window).scroll(function () {
        // 如果document向上卷曲出去的高度 >= 导航栏的高度,则给导航栏设置固定定位,top=0
       if($(document).scrollTop()>=$("#header").height()){
            $("#header").css({"position":"fixed","top":0,"zIndex":"11"});
       }else{
            $("#header").css({"position":"static"});
       }
    });
});
// 周榜弹窗
function showWeekRank(starttime,endtime){
    var top = $(document).scrollTop();
    var div_mask=$('#mask');
    var width=document.body.scrollWidth+'px';
    var height=document.body.scrollHeight+'px';
    div_mask.css({'width':'100%','height':'100%','display':'block','position':'fixed'});
    $('.l_weekBox').css({"display":"block",'position':'fixed'});
    var status=$('.l_weekBox').css('display');
    if(status == "block"){
        // $(".schlist>li").unbind("click",showWeekRank);
    }
    $(document).on('scroll.unable',function (e) {
        $(document).scrollTop(top);
    })
    $.ajax({
        url: rankinglist,
        type: "POST",
        data:  {start_time:starttime,end_time:endtime},
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success: function (data) {
            var data = eval("("+data+")");
            var str = '';
            for(var i =0 ;i < data.length;i++){
               str += '<ul><li><div class="l_photo"><div class="photo">';
               if(data[i].photo){
                    str += '<img src="'+data[i].photo+'">';
               }else{
                   str += '<img src="rankinglist/images/user_tx.png">';
               }
               str +='</div><div class="l_name">';
               str += '<span class="num">NO'+(i+1)+'</span>';
               str += '<span class="name">'+data[i].username+'</span>';
               str += '</div></div><div class="l_dianwei">';
               str += '<span>'+data[i].week_profit+'点</span><span class="dib">周盈利点位</span></div>';
               str += '<div class="l_dianwei"><span style="color: #f73553;font-size:14px;">¥'+(Number(data[i].bonus).toFixed(2))+'</span>';
               str += '<span class="dib">奖金</span></div>';
               str += '</div></div><div class="l_dianwei"><span>';
               if(data[i].status == 1){
                 str += data[i].desc;
               }else{
                 str += '¥'+(Number(data[i].actual_bonus).toFixed(2));
               }
               str += '</span>';
               if(data[i].status == 1){
                    str += '<span class="dib" style="color: #20222c;">未达标';
               }else{
                    if(data[i].allpoint > 0){
                        str += '<span class="dib" style="color: #ff304d;">已达标';
                    }else{
                        str += '<span class="dib" style="color: #ff304d;">已达标(减半)';
                    }
               }
               str +='</span></div></li></ul>';
            }
            $('#l_con').html(str);
        },
        error: function(){}
    });
    $(document).ready(function(){
        $("#l_con").niceScroll({
          cursorborder:"",
          cursorwidth:"10px",
          cursorcolor:"#900c0d",
          boxzoom:true,
          cursoropacitymin: 1,
          background:"#fff",
          autohidemode:false,
      });
    }) 
}
function hideWeekRank(){
    $('.l_weekBox').css({"display":"none"});
    $('#mask').css({"display":"none"});
    $(document).unbind("scroll.unable");
}


// 点击非弹层部分，弹层隐藏
$(document).click(function(){
    if($('.l_weekBang').css('display') == 'block') {
        $('.l_weekBang').hide();
        $("#mask").hide();
    }
})
// 点击×，关闭层
function weekBangclose(){
    $('.l_weekBang').hide();
    $('#mask').hide();
}



function enable_scroll() {
    if (window.removeEventListener) {
        window.removeEventListener('DOMMouseScroll', wheel, false);
    }
    window.onmousewheel = document.onmousewheel = document.onkeydown = null; 
}


// 扫码进群
$('.l_qrcode').toggle(
  function(){
  $('.l_qrcode .code_img').css({'transform':'translateX(0px)','transition':'all 0.4s linear'});},
  function(){
  $('.l_qrcode .code_img').css({'transform':'translateX(390px)'});}
)